<template>
	<view class="account">
		<view class="earningsWrap uniBtn">
			<view>
				<view class="earningsTxt">门诊余额</view>
				<view class="earnings">{{price | NumFormat}}</view>
			</view>
			<view>
				<view class="earningsTxt">推荐收益</view>
				<view class="earnings">{{price2 | NumFormat}}</view>
			</view>
			<!-- <view class="balance">
				提现<text>{{1261.12 | NumFormat}}</text>
				<view class="shu"></view>
				余额<text>{{2454 | NumFormat}}</text>
			</view> -->
		</view>
		
		<view class="uniAround">
			<view :class="active==1?'activeClass':''" @click="tabs(1)">订单收益</view>
			<view :class="active==2?'activeClass':''" @click="tabs(2)">推荐收益</view>
		</view>
		<view class="boxes" v-for="(i,index) in list" :key="index">
			<view class="uniBtn" v-if="active==1">
				<view>
					<view>{{i.pay_type_str}}</view>
					<view class="time">{{i.number}}</view>
				</view>
				<view>+{{i.shouyi | NumFormat}}</view>
			</view>
			<view class="uniBtn" v-else-if="active==2">
				<view>
					<view>{{i.title}}</view>
					<view class="time">{{i.created_at}}</view>
				</view>
				<view>+{{i.price | NumFormat}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		myprice,shouyi1,shouyi2
	} from '../../request/api.js'
	export default {
		data() {
			return {
				price:0,
				price2:0,
				// 上拉加载
				active:1,
				page: 1,
				pages: 0,
				list: []
			}
		},
		onLoad() {
			this.myprice()
			this.getList(1)
		},
		onReachBottom: function() {
			//触底的时候请求数据，即为上拉加载更多
			this.page++;
			if (this.page > this.pages) {
				uni.hideNavigationBarLoading();
				uni.showToast({
					title: '暂无更多数据',
					icon: 'none'
				})
			} else {
				this.getList(this.page);
			}
		},
		methods: {
			tabs(num){
				this.active = num;
				this.list = [];
				this.page = 1;
				this.pages = 0;
				this.getList(1)
			},
			// 列表
			getList(page) {
				var that = this
				uni.showLoading({
					title: '加载中...'
				})
				let strs = shouyi1;
				if(this.active == 2){
					strs = shouyi2; 
				}
				strs({
					page: page,
					listRows: 20,
				}).then(res => {
					this.pages = res.totalPages;
					if (this.page == 1) {
						this.list = res.data;
						if (this.list.length === 0 || this.list.length === '0') {
							uni.showToast({
								icon: 'none',
								duration: 3000,
								title: '暂无数据'
							});
							return
						}
					} else {
						this.list = this.list.concat(res.data);
					}
					uni.hideLoading()
					uni.hideNavigationBarLoading()
				})
			},
			// 获取用户信息
			myprice() {
				myprice().then(res => {
					this.price = res.data.dprice.price;
					this.price2 = res.data.dprice.price3;
				})
			},
		},
		filters: {
			NumFormat: function(value) {
				if (value === "" || value === null || value === undefined) return "-";
				let arr = (value + '').split('.')
				value = Number(arr[0]).toFixed(2);
				let intPart = Math.trunc(value); // 获取整数部分
				let intPartFormat = intPart
					.toString()
					.replace(/(\d)(?=(?:\d{3})+$)/g, "$1,"); // 将整数部分逢三一断
				if(arr[1]){
					return intPartFormat + '.' + arr[1];
				}else{
					return intPartFormat
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	page{
		background: #f8f8f8;
	}
	.account {
		.earningsWrap {
			background: #ffffff;
			padding: 36upx 30upx;
			
			.earningsTxt {
				font-size: 28upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				margin-bottom: 16upx;
			}

			.earnings {
				font-size: 60upx;
				font-family: Helvetica;
				font-weight: bold;
			}

			.balance {
				display: flex;
				align-items: center;
				font-size: 32upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #7B7B7B;

				text {
					color: #414141;
					margin-left: 10upx;
				}

				.shu {
					width: 0upx;
					height: 24upx;
					border: 2upx solid #E5E5E5;
					margin: 0 32upx;
				}
			}
		}
		.uniAround{
			margin: 30upx 0;
			font-size: 32upx;
			.activeClass{
				color: #FF7361;
			}
		}
		.boxes{
			background: #ffffff;
			margin-bottom: 20upx;
			padding: 20upx 30upx;
			
			.time{
				font-size: 26upx;
				color: #7B7B7B;
				margin-top: 20upx;
			}
		}
	}
</style>
